/*
 * @Author: szx
 * @Date: 2022-03-17 14:14:08
 * @LastEditTime: 2022-03-17 14:23:19
 * @Description:
 * @FilePath: \leetcode\800-899\860\860_2.js
 */

/**
 * @param {number[]} bills
 * @return {boolean}
 */
var lemonadeChange = function (bills) {
    const cnt = {
        5: 0,
        10: 0,
        20: 0
    };
    for (let b of bills) {
        if (b == 5) cnt[5]++;
        else if (b == 10) {
            if (cnt[5] > 0) {
                cnt[5]--;
                cnt[10]++;
            } else return false;
        } else {
            if (cnt[10] > 0) {
                cnt[10]--;
                if (cnt[5] > 0) cnt[5]--;
                else return false;
            } else if (cnt[5] > 2) {
                cnt[5] -= 3;
            } else return false;
        }
    }
    return true;
};
